<?
class RequestHandler {
	public function handleRequest($project, $defaultController) {
		$controller = $_GET["controller"];
		if (!$controller) {
			$controller = $defaultController;
		}
	
		$paths = preg_split("/:/", get_include_path());
		$root = $paths[count($paths)-1];
		if (!file_exists("$root/$project/controller/$controller.php")) {
			header("HTTP/1.1 404 Not Found");
			exit();
		}
		require("$project/controller/$controller.php");

		$obj = new $controller();
		if ($_SERVER["REQUEST_METHOD"] == "GET") {
			$obj->doGet();
		} else if ($_SERVER["REQUEST_METHOD"] == "POST") {
			$obj->doPost();
		} else {
			header("HTTP/1.0 405 Method Not Allowed");
			exit();
		}
	}
}
?>
